// Keeping this on hand as a potential alternate approach in the future

//using System;
//using System.Collections.Generic;
//using System.IO;
//using FireStarter.CodeGeneration;
//using FireStarterModeller.BO;
//using Habanero.BO;
//using Habanero.BO.ClassDefinition;
//using Habanero.BO.Loaders;
//using NUnit.Framework;

//namespace FireStarter.Test.CodeGeneration
//{
//    [TestFixture]
//    public class Test_BoTestProjectGenerator_Brett  //: TestBase
//    {
//        [TestFixtureSetUp]
//        public void TestFixtureSetup()
//        {
//            ClassDef.ClassDefs.Clear();
//            ClassDef.LoadClassDefs(new XmlClassDefsLoader(BOBroker.GetClassDefsXml(), new DtdLoader()));


//            //Code that is executed before any test is run in this class. If multiple tests
//            // are executed then it will still only be called once.
//        }
        
//        [SetUp]
//        public void SetupTest()
//        {
//            if (Directory.Exists(TestUtils.TempTestProjectFolder))
//            {
//                Directory.Delete(TestUtils.TempTestProjectFolder, true);
//            }
//            BORegistry.DataAccessor = new DataAccessorInMemory();

//        }
        
//        [TearDown]
//        public  void TearDownTest()
//        {
//            //runs every time any testmethod is complete
//        }

//        //== Things I changed - Removed the base class test class inheritance should be limited to things that really inherit from 
//        // each other. not just to make the methods available to sub classes as static methods.
//        //== moved the parameters from gets and set into constructor. This forces them to be set and can validate in constructor
//        //    instead of what was being done with them being validated in the generate method.
//        //== Moved construction of projectGenerator to use a builder pattern.
//        //== Moved generation to use chain of responsibility.
//        //== Introduces some small classes e.g. Reference. 
//        //== Inheritance of tests changed to so that each piece is tesed independently.

//        [Test]
//        public void Test_SetupProjectGenerator()
//        {
//            //---------------Set up test pack-------------------
//            const string projectName = "TestProject.Test.BO";
//            string boProjectFileName = TestUtils.GetRootedPath(TestUtils.GetRandomProjectFileName());
//            string projectPath = TestUtils.GetRootedPath(Path.Combine(TestUtils.TempTestProjectFolder, TestUtils.GetRandomString()));
//            string habaneroReferencePath = TestUtils.GetRootedPath(Path.Combine(TestUtils.TempTestProjectFolder, TestUtils.GetRandomString()));

//            //---------------Assert Precondition----------------

//            //---------------Execute Test ----------------------
//            BoTestProjectGenerator projectGenerator =
//                new BoTestProjectGenerator(projectName, boProjectFileName, habaneroReferencePath, projectPath, new SolutionGenerator());

//            //---------------Test Result -----------------------
//            Assert.AreEqual(projectName, projectGenerator.ProjectName);
//            Assert.AreEqual(boProjectFileName, projectGenerator.BoProjectFileName);
//            Assert.AreEqual(projectPath, projectGenerator.ProjectPath);
//            Assert.AreEqual(habaneroReferencePath, projectGenerator.HabaneroReferencePath);
//        }

//        [Test]
//        public void Test_SetupProjectGenerator_InvalidProjName()
//        {
//            //---------------Set up test pack-------------------
            
//            //---------------Assert Precondition----------------

//            //---------------Execute Test ----------------------
//            try
//            {
//                new BoTestProjectGenerator(null, null, null, null, null);
//                Assert.Fail("expected Err");
//            }
//            //---------------Test Result -----------------------
//            catch (ArgumentNullException ex)
//            {
//                StringAssert.Contains("projectName", ex.ParamName);
//            }
//            catch (Exception)
//            {
//                Assert.Fail("expected ArgumentNullException");
//            }
//        }


//        [Test]
//        public void Test_Construct_AddsCorrectReferences()
//        {
//            //---------------Set up test pack-------------------
//            BoTestProjectGenerator boTestProjectGenerator = CreateNewTestProject();
            

//            //---------------Assert Precondition----------------
//            Dictionary<string, Reference> references = boTestProjectGenerator.References;
//            Assert.IsFalse(references.ContainsKey("Habanero.Base.dll"));
//            Assert.IsFalse(references.ContainsKey("Habanero.BO.dll"));
//            Assert.IsFalse(references.ContainsKey("Habanero.DB.dll"));
//            Assert.IsFalse(references.ContainsKey("nunit.framework.dll"));

//            //---------------Execute Test ----------------------
//            boTestProjectGenerator.Construct();

//            //---------------Test Result -----------------------
//            string habaneroReferencePath = boTestProjectGenerator.HabaneroReferencePath;
//            references = boTestProjectGenerator.References;
//            AssertReferenceCorrect(references, habaneroReferencePath, "Habanero.Base.dll");
//            AssertReferenceCorrect(references, habaneroReferencePath, "Habanero.BO.dll");
//            AssertReferenceCorrect(references, habaneroReferencePath, "Habanero.DB.dll");
//            AssertReferenceCorrect(references, habaneroReferencePath, "nunit.framework.dll");
//        }

//        [Test]
//        public void Test_Construct_TestBase()
//        {
//            //---------------Set up test pack-------------------
//            BoTestProjectGenerator boTestProjectGenerator = CreateNewTestProject();
//            //---------------Assert Precondition----------------
//            Assert.IsFalse(boTestProjectGenerator.GeneratedClasses.ContainsKey("TestBase"));

//            //---------------Execute Test ----------------------
//            boTestProjectGenerator.Construct();

//            //---------------Test Result -----------------------
//            AssertClassGeneratorCorrect(boTestProjectGenerator, "TestBase");
//        }

//        [Test]
//        public void Test_Construct_TestUtil()
//        {
//            //---------------Set up test pack-------------------
//            BoTestProjectGenerator boTestProjectGenerator = CreateNewTestProject();

//            ProjectFileManager projectFileManager = new ProjectFileManager(boTestProjectGenerator.BoProjectFileName, CodeTemplateEnum.CSharpVisualStudio2005);
//            projectFileManager.SaveProjectFile();
//            //---------------Assert Precondition----------------
//            Assert.IsFalse(boTestProjectGenerator.GeneratedClasses.ContainsKey("TestUtils"));
//            //---------------Execute Test ----------------------
//            boTestProjectGenerator.Construct();
//            //---------------Test Result -----------------------
//            AssertClassGeneratorCorrect(boTestProjectGenerator, "TestUtils");
//            ClassGenerator classGenerator = boTestProjectGenerator.GeneratedClasses["TestUtils"];
//            Assert.IsInstanceOf(typeof(ClassGeneratorTestUtils), classGenerator);
//            ClassGeneratorTestUtils classGeneratorTestUtils = (ClassGeneratorTestUtils)classGenerator;
//            Assert.AreEqual(projectFileManager.AssemblyName, templateParser.BoProjectName);
//        }

//        private static void AssertReferenceCorrect(IDictionary<string, Reference> references, string referencePath, string referenceDllName)
//        {
//            Assert.IsTrue(references.ContainsKey(referenceDllName), "should contain " + referenceDllName);
//            Reference reference = references[referenceDllName];
//            Assert.AreEqual(referencePath, reference.ReferencePath);
//        }

//        [Test]
//        public void Test_Construct_SetsUpProjectFileManager()
//        {
//            BoTestProjectGenerator boTestProjectGenerator = CreateNewTestProject();

//            //---------------Assert Precondition----------------
//            Assert.IsNull(boTestProjectGenerator.ProjectFileManagerBoTest);

//            //---------------Execute Test ----------------------
//            boTestProjectGenerator.Construct();

//            //---------------Test Result -----------------------
//            ProjectFileManager projectFileManagerBoTest = boTestProjectGenerator.ProjectFileManagerBoTest;
//            Assert.IsNotNull(projectFileManagerBoTest);
//            Assert.AreEqual(boTestProjectGenerator.ProjectFileName, projectFileManagerBoTest.ProjectFileName);
//            Assert.AreEqual(boTestProjectGenerator.ProjectName, projectFileManagerBoTest.AssemblyName);
//            Assert.AreEqual(boTestProjectGenerator.ProjectName, projectFileManagerBoTest.RootNamespace);
//        }

//        [Test]
//        public void Test_ConstructAdds_BoTestFiles()
//        {
//            //---------------Set up test pack-------------------
//            BoTestProjectGenerator boTestProjectGenerator = CreateNewTestProject();
//            IModelClass dmClass = new DMClass();
//            dmClass.ClassName = TestUtils.GetRandomString();
//            boTestProjectGenerator.SolutionGenerator.ModelClasses.Add(dmClass);

//            //---------------Assert Precondition----------------
//            Assert.IsFalse(boTestProjectGenerator.GeneratedClasses.ContainsKey(dmClass.ClassName));

//            //---------------Execute Test ----------------------
//            boTestProjectGenerator.Construct();

//            //---------------Test Result -----------------------
//            AssertClassGeneratorCorrect(boTestProjectGenerator, dmClass.ClassName);
//        }
//        [Test]
//        public void Test_ConstructAdds_BoTestFiles_2Classes()
//        {
//            //---------------Set up test pack-------------------
//            BoTestProjectGenerator boTestProjectGenerator = CreateNewTestProject();
//            IModelClass modelClass1 = AddModelClassToProjectGenerator(boTestProjectGenerator);
//            IModelClass modelClass2 = AddModelClassToProjectGenerator(boTestProjectGenerator);

//            //---------------Assert Precondition----------------
//            Assert.IsFalse(boTestProjectGenerator.GeneratedClasses.ContainsKey(modelClass1.ClassName));
//            Assert.IsFalse(boTestProjectGenerator.GeneratedClasses.ContainsKey(modelClass2.ClassName));

//            //---------------Execute Test ----------------------
//            boTestProjectGenerator.Construct();

//            //---------------Test Result -----------------------
//            AssertClassGeneratorCorrect(boTestProjectGenerator, modelClass1.ClassName);
//            AssertClassGeneratorCorrect(boTestProjectGenerator, modelClass2.ClassName);
//        }

//        private static IModelClass AddModelClassToProjectGenerator(BoTestProjectGenerator boTestProjectGenerator)
//        {
//            IModelClass dmClass = new DMClass();
//            dmClass.ClassName = TestUtils.GetRandomString();
//            boTestProjectGenerator.SolutionGenerator.ModelClasses.Add(dmClass);
//            return dmClass;
//        }

//        [Test]
//        public void Test_Compile()
//        {
//            //---------------Set up test pack-------------------
//            BoTestProjectGenerator boTestProjectGenerator = CreateNewTestProject();
//            boTestProjectGenerator.Construct();

//            //---------------Assert Precondition----------------

//            //---------------Execute Test ----------------------
//            boTestProjectGenerator.Compile();

//            //---------------Test Result -----------------------

//            // Sets up the AssemblyInfo content from the template
//            string assemblyInfoContents = boTestProjectGenerator.AssemblyInfoFileContents;
//            StringAssert.Contains(string.Format("[assembly: AssemblyTitle(\"{0}\")]", boTestProjectGenerator.ProjectName), assemblyInfoContents);
//            StringAssert.Contains(string.Format("[assembly: AssemblyProduct(\"{0}\")]", boTestProjectGenerator.ProjectName), assemblyInfoContents);
//            AssertAssemblyGuidReplaced(assemblyInfoContents);

//            // Adds all the necessary references to the ProjectFileManager
//            ProjectFileManager projectFileManagerBoTest = boTestProjectGenerator.ProjectFileManagerBoTest;
//            AssertAllReferencesSet(boTestProjectGenerator.References, projectFileManagerBoTest);
            
//            // Adds all the necessary files to the ProjectFileManager
//            //  AssemblyInfo, and all Code Files
//            string assemblyInfoFileName = Path.Combine(boTestProjectGenerator.ProjectPath, @"Properties\AssemblyInfo.cs");
//            Assert.IsTrue(projectFileManagerBoTest.HasCodeFile(assemblyInfoFileName));
//            AssertAllCodeFilesAddedToProject(boTestProjectGenerator.ProjectPath, boTestProjectGenerator.GeneratedClasses, projectFileManagerBoTest);
//        }

//        private static void AssertAllCodeFilesAddedToProject(string projectPath, Dictionary<string, ClassGenerator> generatedClasses, ProjectFileManager projectFileManagerBoTest)
//        {
//            foreach (ClassGenerator classGenerator in generatedClasses.Values)
//            {
//                string codeFileName = Path.Combine(projectPath, classGenerator.FileName);
//                Assert.IsTrue(projectFileManagerBoTest.HasCodeFile(codeFileName));
//            }
//        }

//        [Test]
//        public void Test_Compile_RunsCompileForAllClassGenerators()
//        {
//            //---------------Set up test pack-------------------
//            BoTestProjectGenerator boTestProjectGenerator = CreateNewTestProject();
//            boTestProjectGenerator.Construct();
//            boTestProjectGenerator.GeneratedClasses.Clear();
//            string fileName = TestUtils.GetRandomString();
//            MockClassGenerator mockClassGanerator1 = new MockClassGenerator(fileName, boTestProjectGenerator.ProjectName, boTestProjectGenerator.ProjectPath);
//            boTestProjectGenerator.GeneratedClasses.Add(fileName, mockClassGanerator1);
//            fileName = TestUtils.GetRandomString();
//            MockClassGenerator mockClassGanerator2 = new MockClassGenerator(fileName, boTestProjectGenerator.ProjectName, boTestProjectGenerator.ProjectPath);
//            boTestProjectGenerator.GeneratedClasses.Add(fileName, mockClassGanerator2);
//            //---------------Assert Precondition----------------

//            //---------------Execute Test ----------------------
//            boTestProjectGenerator.Compile();
//            //---------------Test Result -----------------------
//            //Runs the Compile method on all the Class Generators
//            Assert.IsTrue(mockClassGanerator1.IsCompiled);
//            Assert.IsTrue(mockClassGanerator2.IsCompiled);
//        }

//        private class MockClassGenerator : ClassGenerator
//        {
//            private bool _isCompiled;

//            public MockClassGenerator(string fileName, string projectName, string projectPath) : base(fileName, projectName, projectPath)
//            {
//            }

//            public bool IsCompiled
//            {
//                get { return _isCompiled; }
//            }

//            public override void Compile()
//            {
//                _isCompiled = true;
//            }

//            public override void GenerateCode()
//            {
//                throw new NotImplementedException();
//            }

//            public override string GetValueReplacementContent(string tagContent)
//            {
//                throw new NotImplementedException();
//            }

//            public override IList<IModelClass> GetModelElementsCollection(string tagContent)
//            {
//                throw new NotImplementedException();
//            }
//        }

//        private static void AssertAllReferencesSet(Dictionary<string, Reference> references, ProjectFileManager projectFileManagerBoTest)
//        {
//            foreach (Reference reference in references.Values)
//            {
//                Assert.IsTrue(projectFileManagerBoTest.HasReference(reference.FullReferencePath));
//            }
//        }

//        private static void AssertAssemblyGuidReplaced(string assemblyInfoContents)
//        {
//            Assert.AreEqual(-1, assemblyInfoContents.IndexOf("[assembly: Guid(\"\")]", 0, StringComparison.InvariantCultureIgnoreCase));
//        }


//        private static void AssertClassGeneratorCorrect(BoTestProjectGenerator boTestProjectGenerator, string testClassName)
//        {
//            Assert.IsTrue(boTestProjectGenerator.GeneratedClasses.ContainsKey(testClassName));
//            ClassGenerator generator = boTestProjectGenerator.GeneratedClasses[testClassName];
//            Assert.AreEqual(testClassName + ".cs", generator.FileName);
//            Assert.AreEqual(boTestProjectGenerator.ProjectName, generator.ProjectName);
//            Assert.AreEqual(boTestProjectGenerator.ProjectPath, generator.ProjectPath);
//        }

//        private static BoTestProjectGenerator CreateNewTestProject()
//        {
//            const string projectName = "TestProject.Test.BO";
//            string boProjectFileName = TestUtils.GetRootedPath(TestUtils.GetRandomProjectFileName());
//            string projectPath = TestUtils.GetRootedPath(Path.Combine(TestUtils.TempTestProjectFolder, TestUtils.GetRandomString()));
//            string habaneroReferencePath = TestUtils.GetRootedPath(Path.Combine(TestUtils.TempTestProjectFolder, TestUtils.GetRandomString()));
//            return new BoTestProjectGenerator(projectName, boProjectFileName, habaneroReferencePath, projectPath, new SolutionGenerator());
//        }

//        [Test]
//        public void Test_ConstructReference()
//        {
//            //---------------Set up test pack-------------------

//            //---------------Assert Precondition----------------

//            //---------------Execute Test ----------------------
//            Reference reference = new Reference("some path", "someName");
//            //---------------Test Result -----------------------
//            Assert.AreEqual("someName", reference.ReferenceDllName);
//            Assert.AreEqual("some path", reference.ReferencePath);
//            Assert.AreEqual(@"some path\someName", reference.FullReferencePath);
//        }
//    }
//}